package com.instagram.instadownloader.fragment;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.vine.vinedownloader.R;
import com.instagram.instadownloader.SearchActivity;
import com.instagram.instadownloader.fragment.base.InstagramFragment;
import com.instagram.instadownloader.utils.Launcher;

public class MenuFragment extends InstagramFragment implements OnClickListener {

	public static final String RATE_APP_PAKAGE_NAME = "";
	public static final String EMAIL_FOR_SEND_FEEDBACK = "";
	
	private EditText edtSearch;
	@Override
	protected View onCreateContentView(LayoutInflater inflater,
			ViewGroup container) {
		View v = inflater.inflate(R.layout.fragment_menu, container, false);
		edtSearch = (EditText) v.findViewById(R.id.edtSearch);
		
		edtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
		    @Override
		    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
		        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
		        	searchAction();      
		            return true;
		        }
		        return false;
		    }
		});
		
		
		((ImageView)v.findViewById(R.id.btnSearch)).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				searchAction();
			}
		});
		v.findViewById(R.id.llRateUs).setOnClickListener(this);
		v.findViewById(R.id.llSendFeedBack).setOnClickListener(this);
		v.findViewById(R.id.llFreeApp).setOnClickListener(this);
		v.findViewById(R.id.llMoreApp).setOnClickListener(this);
		v.findViewById(R.id.llInstaDownload).setOnClickListener(this);
		v.findViewById(R.id.llTwitterDownload).setOnClickListener(this);
		return v;
	}
	private void searchAction(){
		 if(!edtSearch.getText().toString().trim().isEmpty()){
      	   Intent i = new Intent(getInstaActivity(), SearchActivity.class);
      	   i.putExtra("keyword", edtSearch.getText().toString());
      	   getInstaActivity().startActivity(i);	
		 }
	}
	
	public void rateApp(){
		Launcher.launchPackageInMarket(getActivity(), "");
	}
	
	public void sendFeedBack(){
		Intent Email = new Intent(Intent.ACTION_SEND);
        Email.setType("text/email");
        Email.putExtra(Intent.EXTRA_EMAIL, new String[] { EMAIL_FOR_SEND_FEEDBACK });
        Email.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
        Email.putExtra(Intent.EXTRA_TEXT, "Dear ...," + "");
        startActivity(Intent.createChooser(Email, "Send Feedback:"));
	}
	
	public void moreApp(){
		
	}
	
	public void openTwitterFanPage(){
		Launcher.openWebView(getActivity(), "https://twitter.com/SaveSocialVideo");
	}
	
	public void openInstaFanPage(){
		Launcher.openWebView(getActivity(), "http://instagram.com/p/d4hneEGV4X/");
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.llRateUs:
			rateApp();
			break;
		case R.id.llSendFeedBack:
			sendFeedBack();
			break;
		case R.id.llFreeApp:
	
			break;
		case R.id.llMoreApp:
	
			break;
		case R.id.llTwitterDownload:
			openTwitterFanPage();
			break;
		case R.id.llInstaDownload:
			openInstaFanPage();
			break;
		default:
			break;
		}
	}
}
